// 例子9

{
    let [foo = true] = [];
    console.log(foo); // true
}

console.log('----------------------------------')

{
    let [x, y = 'y'] = ['x'];
    console.log(x, y); // "x" "y"
}

console.log('----------------------------------')

{
    let [a, b = 'b'] = ['a', undefined];
    console.log(a, b); // "a" "b"
}

console.log('----------------------------------')

{
    let [z = 1] = [null];
    console.log(z); // null
}

console.log('----------------------------------')

{
    function fn(x) {
        console.log(x);
        return x;
    }
    let [bar = fn('bar')] = [1];
    let [baz = fn('baz')] = [];
    console.log(bar, baz); // 1 "baz", 这里bar中的fn('bar')并没有执行
}

console.log('----------------------------------')

{
    let [x1 = 1, y1 = x1] = [];
    console.log(x1, y1); // 1 1

    let [x2 = 1, y2 = x2] = [2];
    console.log(x2, y2); // 2 2

    let [x3 = 1, y3 = x3] = [5, 10];
    console.log(x3, y3); // 5 10

    let [x4 = y4, y4 = 1] = [2];
    console.log(x4, y4); // 2 1

    let [x5 = y5, y5 = 1] = [];
    console.log(x5, y5); // Uncaught ReferenceError: y5 is not defined
}